package main.java.indi.zyj.coderecord;

public class Change2 {



    public int change1(int amount, int[] coins) {

        int[] dp = new int[amount + 1];
        dp[0] = 1;

        for (int i = 0; i < coins.length; i++) {
            for (int j = 1; j < amount + 1; j++) {
                if (j - coins[i] >= 0) {
                    dp[j] += dp[j - coins[i]];
                }
            }
        }
        return dp[amount];

    }



    public int change(int amount, int[] coins) {


        // dp[i] 表示i块钱最多有dp[i]种更换方法
        int[] dp = new int[amount + 1];
        dp[0] = 1;

        // 如果求组合数就是外层for循环遍历物品，内层for遍历背包。
        for (int i = 0; i < coins.length; i++) {
            for (int j = 1; j <= amount; j++) {
                if (j - coins[i] >= 0) {
                    dp[j] += dp[j - coins[i]];
                }
            }
        }

        return dp[amount];

    }

}
